/*
 * @Author: jiu yin
 * @Date: 2024-05-08 14:14:22
 * @LastEditTime: 2024-06-04 18:15:21
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \studio-web-admin\src\view\ticket_order\component\Tables.tsx
 * jiu
 */
import { useState, useRef } from "react";
import { Radio, ConfigProvider, Input, Image, Button } from "antd";
import "./index.scss";
import { ProTable } from "@ant-design/pro-components";
import type { ActionType } from "@ant-design/pro-components";
import { list_ticket_order, get_order_ticket_list } from "@/api/home";
import User_avatar from "@/comment/user_avatar";
import { thousands } from "@/utils";
import { WechatFilled, AlipayCircleFilled } from "@ant-design/icons";

export default function index(props: any) {
	const { radioValue } = props;

	const actionRef = useRef<ActionType>(null);

	let [params, set_params] = useState({ keyword: "" });

	const reload = () => {
		actionRef.current && actionRef.current.reload();
	};

	const columns = [
		{
			dataIndex: "index",
			valueType: "indexBorder",
			width: 48,
		},
		{
			title: "订单编号/时间",
			dataIndex: "nickname",
			hideInSearch: true,
			render: (_: any, item: any) => (
				<div className=" text-14px">
					<p className="c-#9e9fb0">
						订单号：<span className="c-#323557">{item.order_no}</span>
					</p>
					<p className="c-#9e9fb0">
						出票时间<span className="c-#323557">{item.created_at}</span>
					</p>
				</div>
			),
		},

		{
			title: "下单用户  ",
			dataIndex: "nickname",
			hideInSearch: true,
			render: (_: any, item: any) => (
				<User_avatar
					options={{
						avatar_url: item.avatar_url,
						nickname: item.nickname,
						id: item.user_id,
					}}
				/>
			),
		},
		{
			title: "含票数量",
			dataIndex: "num",
			hideInSearch: true,
		},

		{
			title: "订单金额",
			dataIndex: "pay_price",
			hideInSearch: true,
			render: (_: any, item: any) => <span>￥ {thousands(item.pay_price)}</span>,
		},
	];

	return (
		<div className="base_bg_fff entrance ">
			<Input
				placeholder="请输入该订单编号"
				style={{ width: 700 }}
				onChange={(e: any) => set_params({ ...params, keyword: e.target.value })}
			/>
			<div className="mt-20px ml--24px">
				<ConfigProvider>
					<ProTable
						columns={columns}
						actionRef={actionRef}
						params={params}
						rowSelection={{
							type: "radio",
							onSelect: record => {
								radioValue(record);
							},
						}}
						request={async (params, sort, filter) => {
							let { data } = await list_ticket_order({
								page: params.current,
								limit: params.pageSize,
								status: 1, //待出票
								...params,
							});
							data.data.forEach((item: any, index: number) => (item.key = index + 1));
							return {
								data: data.data,
								success: true,
								total: data.total,
							};
						}}
						rowKey="key"
						tableAlertRender={false}
						search={false}
						options={false}
						pagination={{
							pageSize: 10,
							hideOnSinglePage: true,
						}}
						dateFormatter="string"
					/>
				</ConfigProvider>
			</div>
		</div>
	);
}
